﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;

namespace MyWeb.Data
{
    public class UserController : SqlDataProvider
    {
        #region[User_GetbyAll]
		public DataTable User_GetByAll()
		{
			using (var cmd = new SqlCommand("sp_User_GetByAll", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[User_GetbyId]
		public DataTable User_GetById(string Id)
		{
			using (var cmd = new SqlCommand("sp_User_GetById", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@_aid", Id));
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion

        #region[User_CheckLogin]
        public DataTable User_CheckLogin(string UserName,string Password)
        {
            using (var cmd = new SqlCommand("sp_User_CheckLogin", GetConnection()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@_aname", UserName));
                cmd.Parameters.Add(new SqlParameter("@_apassword", Password));
                var da = new SqlDataAdapter(cmd);
                var dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        #endregion
		#region[User_GetbyTop]
		public DataTable User_GetByTop(string Where)
		{
			using (var cmd = new SqlCommand("sp_User_GetByTop", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				cmd.Parameters.Add(new SqlParameter("@Where",Where));
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[User_Insert]
		public void User_Insert(UserInfo Data)
		{
			using (var cmd = new SqlCommand("sp_User_Insert", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@_aname", Data.UserName));
				cmd.Parameters.Add(new SqlParameter("@_apassword", Data.Password));
				cmd.Parameters.Add(new SqlParameter("@_arole", Data.Role));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
		#region[User_Update]
		public void User_Update(UserInfo Data)
		{
			using (var cmd = new SqlCommand("sp_User_Update", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@_aid", Data.Id));
				cmd.Parameters.Add(new SqlParameter("@_aname", Data.UserName));
				cmd.Parameters.Add(new SqlParameter("@_apassword", Data.Password));
				cmd.Parameters.Add(new SqlParameter("@_arole", Data.Role));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
		#region[User_Delete]
		public void User_Delete(string Id)
		{
			using (var cmd = new SqlCommand("sp_User_Delete", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@_aid", Id));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
	}
    
}
